<?php
$user="junemann_nl";
$password="";
$database="junemann_nl";

$con = mysql_connect("localhost",$user,$password);
if(!$con)
{
	die("Unable to connect to server");
}

mysql_select_db($database, $con);

$id = $_GET["id"];
$datetime = $_GET["datetime"];
$characterid= $_GET["characterid"];
$itemid= $_GET["itemid"];
$isoffspec = $_GET["isoffspec"];

echo "<?xml version='1.0' encoding='UTF-8'?><items>";

if($id == "-1")
{
   // New item. Insert
   mysql_query("INSERT INTO null_sk_loot(DateTime, CharacterID, ItemID, IsOffspec) VALUES(NOW(), " .$characterid. ", " .$itemid. ", " .$isoffspec. ")");
   
   // Return ID for check and update
   $result = mysql_query("SELECT * FROM null_sk_loot ORDER BY ID DESC LIMIT 0 , 1");
   while($row = mysql_fetch_array($result))
   {
      echo "<loot id='". $row['ID'] ."' datetime='" . $row['DateTime'] . "' itemid='" . $row['ItemID'] . "' isoffspec='" . $row['IsOffspec'] . "' />";
   }
 }
 else
 {
   // Update.
   mysql_query("UPDATE null_sk_loot SET DateTime = " . $datetime . ", CharacterID = '" . $characterid . "' , ItemID = '" . $itemid . "' , IsOffspec = '" . $isoffspec. "' WHERE ID = " .$id);
   
   // Return ID for check and update
   $result = mysql_query("SELECT * FROM null_sk_loot WHERE ID = " .$id);
   while($row = mysql_fetch_array($result))
   {
      echo "<loot id='". $row['ID'] ."' datetime='" . $row['DateTime'] . "' itemid='" . $row['ItemID'] . "' isoffspec='" . $row['IsOffspec'] . "' />";
   }   
 }
 
echo "</items>";

mysql_close($con);
?>